﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BASE;



public partial class Admin_dstin : System.Web.UI.Page
{
    public int cout = 1;
    protected void Page_Load(object sender, EventArgs e)
    {
        //check quyen vao trang

        if (Utils.getIntSession("userid") == 0)
        {
            Response.Redirect("/admin/login.aspx");
        }
        busMenu busM = new busMenu();
        if (!busM.checkQuyenVaoTrang(Utils.getIntSession("userid"), Constants.ADMIN_DSTINTUC))
        {
            Response.Redirect("/admin/");
        }


        Session["trang"] = Constants.ADMINTINTUC;
        dr_lt.SelectedIndexChanged += new EventHandler(dr_lt_SelectedIndexChanged);
        gr_tin.RowCommand += new GridViewCommandEventHandler(gr_tin_RowCommand);
        //check quyen vao trang

        if (Utils.getIntSession("quyenid") != 1)
        {
            Response.Redirect("/admin");
        }
        if (!IsPostBack)
        {
            binLoaiTin();
            binData();
        }

        
    }
    void binData()
    {
        busTin busT = new busTin();
        List<entTin> lst = new List<entTin>();
        lst = busT.getTinByLoaiTinId(int.Parse(dr_lt.SelectedValue));
        gr_tin.DataSource = lst;
        gr_tin.DataBind();
    }
    void gr_tin_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "del")
        {
            busTin busT = new busTin();
            busT.delete(int.Parse(e.CommandArgument.ToString()));
            binData();
        }
    }

    void dr_lt_SelectedIndexChanged(object sender, EventArgs e)
    {
        busTin busT = new busTin();
        List<entTin> lst = new List<entTin>();
        lst = busT.getTinByLoaiTinId(int.Parse(dr_lt.SelectedValue));
        gr_tin.DataSource = lst;
        gr_tin.DataBind();
    }
    void binLoaiTin()
    {
        busLoaiTin busLT = new busLoaiTin();
        dr_lt.DataSource = busLT.getAll();
        dr_lt.DataTextField = "TenLoaiTin";
        dr_lt.DataValueField = "LoaiTinId";
        dr_lt.DataBind();
    }
}